@/*
    人员部门群组选择说明
    id:文本框id
    name：文本框名字
    value : value
    textValue :textValue
    isMulti:多选true,单选false 不填写默认单选
    传参：在后台传参需要获取$("#id").val()以及$("#id_text").val()一个是主键一个是名称
    单选情况下：返回user的id："id"
    多选情况下：会返回字符串"id1,id2,id3",比如"111111,22222,3333333"
@*/
@if(isEmpty(textValue)){
@	textValue=null;
@}
@if(isEmpty(value)){
@	value=null;
@}
@if(isEmpty(isMulti)){
@	isMulti=false;
@}else{
@	isMulti=isMulti=="false"?false:true;
@}
@if(isEmpty(width)){
@	width="100%";
@}
<div class="form-group">
    @if(!isEmpty(name)){
        <label class="lab">${name}</label>
    @}
	<div class="ele ${isEmpty(name)?'ele-fit':''}">
	    @if(isMulti){
	        <textarea class="textbox" id="${id}_text" name="${id}_text" style="float:left;width:${width!};margin: 0px">${textValue!}</textarea>
	    @}else{
	    	<input class="textbox" id="${id}_text" name="${id}_text" value="${textValue!}" type="text" style="float:left;${width!};margin: 0px"/>
	    @}
    	<i class="clearicon" id="${id}_clear"></i>
    	<input style="width:100%" type="hidden" id="${id}" name="${id}" value="${value!}">
		@if(isNotEmpty(tips)){
	        <span class="help-block m-b-none">${tips!}</span>
		@}
	</div>
</div>
<script type="text/javascript">
	$("#${id}_text").click(function(){
        var _text_id = "${id}_text";
        var _value_id = "${id}";
        var ids = $("#"+_value_id).val();
        var isMulti=${isMulti};
        var opt = {
            type: 2,
            title: '选择人员',
            area: ['517px', '470px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: '/static/common/_user_selecttree.html',
            success: function(layero, index){
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                iframeWin.isMulti = isMulti;
                iframeWin.initOrgTree(Sys.backendPath + "/tree/user",ids);
                iframeWin.initPublicGroupTree(Sys.backendPath + "/tree/group/public");
                iframeWin.initPrivateGroupTree(Sys.backendPath + "/tree/group/personal");
            }
        }

        opt["btn"]=[];
        opt.btn.push('<i class="fa fa-check"></i> 确定');
        opt['btn'+opt.btn.length] = function(index, layero){
            var win = window[layero.find('iframe')[0]['name']];
            win.$('#keyword').val('').change();
            var codes = [], names = [];
            var map =  win.mapData;
            console.log(map)
                $.each(map, function (key, values) {
                    if (values != "") {
                        var code = (key || values) + "", name = values;
                        codes.push(code.replace(/^u_/g, ''));
                        names.push(name.replace(/\([0-9]*\)/g, ''));
                    }
                });
                $("#" + _value_id).val(codes.join(',')).change();
                $("#" + _text_id).val(names.join(',')).change();
            var index = layer.getFrameIndex(layero.find('iframe')[0]['name']); //获取窗口索引
            layer.close(index);
        };
        opt.btn.push('<i class="fa fa-eraser"></i> 清除');
        opt['btn'+opt.btn.length] = function(index, layero){
            var win = window[layero.find('iframe')[0]['name']];
            win.allClear();
            return false;
        };
        opt.btn.push('<i class="fa fa-close"></i> 关闭');
        opt['btn'+opt.btn.length] = function(index, layero){
            var index = layer.getFrameIndex(layero.find('iframe')[0]['name']); //获取窗口索引
            layer.close(index);
        };
        layer.open(opt);
    })

	$("#${id}_clear").click(function(){
        $('#${id}_text').val('').change();
        $('#${id}').val('').change();
    })
</script>

